package ooseminar.parking;

import java.util.HashMap;
import java.util.Map;

public class ParkingLots {
    private int size;
    private Map<Object, Car> lots;

    public ParkingLots(int size) {
        this.size = size;
        lots = new HashMap<Object, Car>();
    }

    public Object park(Car car) {
        if (lots.size() == size)
            return null;
        Object ticket = new Object();
        lots.put(ticket, car);
        return ticket;
    }

    public Car unpark(Object ticket) {
        if (size == 0 || !lots.containsKey(ticket))
            return null;
        return lots.remove(ticket);
    }

    public <T> T get(NonComericalBasedChooserRateContextAction<T> calculation) {
        return calculation.calculate(this.size, this.size - lots.size());
    }

    public String Report() {
        return String.format("PL %d/%d", lots.size(), size);
    }

    static interface NonComericalBasedChooserRateContextAction<T> {
        T calculate(int size, int idle);
    }

    static interface ComericalBasedChooserRateContextAction<T> {
        T calculate(int size, int idle, double hourlyRate);
    }

}
